<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="../vue.js"></script>
</head>

<body>
    <!-- 接口1：请求地址：https://autumnfish.cn/api/joke/list 
        请求方法：get 
        请求参数：num 
        响应内容：随机笑话 -->
    <div id='a'>
        <input type="button" value="获取笑话" @click="huoqu">
        <p>{{joke}}</p>
    </div>
    <script>
        new Vue({
            el: '#a',
            data: {
                joke: "hahah"
            },
            methods: {
                huoqu: function() {
                    //console.log(this);这里的this是上面的vue对象
                    var that = this;
                    axios.get("https://autumnfish.cn/api/joke/list?num=1").then(function(response) {;

                        that.joke = response.data.jokes[0];
                        //console.log(this);这里的this是window对象
                    }, function(err) {
                        console.log(err);

                    })
                }
            }
        })
    </script>
</body>

</html>